package com.uduemc.biso.module.basic.service.customer.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.github.pagehelper.page.PageMethod;
import com.uduemc.biso.core.extities.center.CustomerRole;
import com.uduemc.biso.core.extities.center.custom.CustomerUserRole;
import com.uduemc.biso.module.basic.service.customer.mapper.CustomerRoleMapper;
import com.uduemc.biso.module.basic.service.customer.mapper.custom.CustomCustomerRoleMapper;
import com.uduemc.biso.module.basic.service.customer.service.CustomerRoleService;

@Service
public class CustomerRoleServiceImpl implements CustomerRoleService {

	@Autowired
	private CustomCustomerRoleMapper customCustomerRoleMapper;

	@Autowired
	private CustomerRoleMapper customerRoleMapper;

	@Override
	public List<CustomerUserRole> findCustomerUserRoleByCustomerId(Long customerId) {
		List<CustomerUserRole> findCustomerUserRoleByCustomerId = customCustomerRoleMapper
				.findCustomerUserRoleByCustomerId(customerId);
		return findCustomerUserRoleByCustomerId;
	}

	@Override
	public CustomerRole insert(CustomerRole customerRole) {
		customerRoleMapper.insertSelective(customerRole);
		return findOne(customerRole.getId());
	}

	@Override
	public CustomerRole updateById(CustomerRole customerRole) {
		customerRoleMapper.updateByPrimaryKeySelective(customerRole);
		return findOne(customerRole.getId());
	}

	@Override
	public CustomerRole findOne(Long id) {
		return customerRoleMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<CustomerRole> findAll(Pageable pageable) {
		int pageNumber = pageable.getPageNumber();
		int pageSize = pageable.getPageSize();
		PageMethod.startPage(pageNumber, pageSize);
		return customerRoleMapper.selectAll();
	}

	@Override
	public void deleteById(Long id) {
		customerRoleMapper.deleteByPrimaryKey(id);
	}

}
